// -*- C++ -*-

#include "Service_Type.h"
#include "tool.h"

void Service_Type::dump(void)
{

}

Service_Type::Service_Type(const char *n, 
						   Service_Type_Impl *o,
						   const DLL &dll, 
						   int active)
						   :name_(0),
						   type_(o),
						   dll_(dll),
						   active_(active),
						   fini_already_called_(0)
{
	this->name( n );
}

Service_Type::Service_Type(const char *n,
						   Service_Type_Impl *o,
						   SHLIB_HANDLE handle,
						   int active)
						   :name_(0),
						   type_(o),
						   active_(active),
						   fini_already_called_(0)
{
	DLL& dll = const_cast<DLL&>(this->dll_);
	dll.set_handle(handle);
	this->name(n);
}

Service_Type::~Service_Type(void)
{
	this->fini();
	delete []const_cast<char*>(this->name_);
}

int Service_Type::fini(void)
{
	if ( !this->fini_already_called_ )
	{
		this->fini_already_called_ = 1;
		return this->type_->fini();
	}
	return 0;
}

int Service_Type::suspend(void) const
{
	(const_cast<Service_Type*>(this))->active_ = 0;
	return this->type_->suspend();
}

int Service_Type::resume(void) const
{
	(const_cast<Service_Type*>(this))->active_ = 1;
	return this->type_->resume();
}

void Service_Type::name( const char* n )
{
	delete []const_cast<char*>( this->name_ );
	this->name_ = Tool::strnew( n );
}

const char* Service_Type::name(void) const
{
	return this->name_;
}

const Service_Type_Impl* Service_Type::type(void) const
{
	return this->type_;
}

void Service_Type::type(const Service_Type_Impl* o, int enabled )
{
	this->type_ = o;
	((ACE_Service_Type *) this)->active_ = enabled;
}

int Service_Type::active(void) const
{
	return this->active_ != 0;
}

void Service_Type::active(int turnon)
{
	this->active_ = turnon;
}

int Service_Type::fini_called(void) const
{
	return this->fini_already_called_;
}